﻿@model IEnumerable<NetSurveillance.WebApp.Models.HostModel>
@{
    ViewBag.Title = "主机名修改";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2 id="title">为了方便查看,建议修改为：名称/IP/MAC</h2>
<link href="@Url.Content("~/Content/MainStyle.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
 @Html.ValidationMessage("Error")
<table id="tabList">
    <tr>
        <th>MAC地址
        </th>
        <th>用户名称
        </th>
        <th>IP地址
        </th>

    </tr>
    @foreach (var item in Model)
    {
        <tr id="@item.id" onmousemove="mouseMove()" onmouseout="mouseOut()" onclick="dobClick()">
            <td>
                @Html.DisplayFor(modelItem => item.Mac)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.HostName)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IP)
            </td>


        </tr>
    }

</table>
新用户名：<input name="newName" id="newName" /><input type="hidden" id="hidID" />
<input type="button" value="修改" onclick="alterEntry();" />
<input type="button" value="退出" onclick="quitEntry();" />
@section css{
    <style type="text/css">
        #title
        {
            color: red;
            font-weight: bold;
            font-family: "微软雅黑";
        }

        #tabList
        {
            margin-left: auto;
            margin-right: auto;
            width: 100%;
            overflow: auto;
        }
    </style>
}
@section javascript
{
    <script type="text/javascript">
        function alterEntry(searchId) {
            var hostid = document.getElementById("hidID").value;
            var txt = document.getElementById("newName").value;
            if (!hostid && !txt) { alert("请先选中修改的用户名！"); return; }
            else {
                window.location.href = '@Url.Action("ChangeName")' + '?hostId=' + hostid + '&txt=' + txt;
            }
           @* $.showLoading('Modify now,please wait');
            $.ajax({
                url: '@Url.Action("ChangeName")',
                type: 'post',
                dataType: 'json',
                data: { hostId: hostid, txt: txt },
                success: function (result) {
                    if (result.Success) {
                        $('#newName').val();
                    } else {
                        alert(result.Message);
                    }
                    $.hideLoading();
                }
            });*@
        }

        function mouseMove() {
            var the_obj = event.srcElement;
            if (the_obj.tagName.toLowerCase() == "td") {
                the_obj = the_obj.parentElement;
                the_obj.style.backgroundColor = 'red';
            }
        }
        function mouseOut() {
            var the_obj = event.srcElement;
            if (the_obj.tagName.toLowerCase() == "td") {
                the_obj = the_obj.parentElement;
                the_obj.style.backgroundColor = '';
            }
        }

        function dobClick() {
            var the_obj = event.srcElement;
            if (the_obj.tagName.toLowerCase() == "td") {
                the_obj = the_obj.parentElement;
                if (the_obj != null && the_obj != undefined) {
                    var txt = document.getElementById("newName");
                    var hidID = document.getElementById("hidID");
                    txt.value = the_obj.cells[1].innerText.trim();
                    hidID.value = the_obj.id;
                }
            }
        }

        String.prototype.trim = function () {
            return this.replace(/(^\s*)|(\s*$)/g, "");
        }

        function quitEntry() {
            window.location.href = '@Url.Action("index", "Search")';
        }
    </script>
}